VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "DAOProducto"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit
Private mvarConnection As utilConexion
Public Property Set Connection(ByVal vData As utilConexion)
    Set mvarConnection = vData
End Property
Public Function eliminar(bean As bproducto) As Integer
On Error GoTo hnderr
Dim sql As String
sql = "SELECT * FROM proc_producto_actualiza ('" + bean.sDescripcionCorta + "','" + bean.sDescripcionLarga + "'," + CStr(bean.nPrecio) + "," + CStr(bean.bestado.nCodigo) + "," + CStr(bean.bCategoria.nCodigo) + ",'" + bean.sCodBarra + "'," + CStr(bean.nCodigo) + ")"
mvarConnection.Connection.Execute sql
eliminar = UtilConstantes.OPT_DATOS_ELIMINADOS
hnderr:
If Err.Number = 0 Then Exit Function
eliminar = UtilConstantes.OPT_ERROR_ENCONTRADO
Err.Clear
End Function
'---------------------------------------------------------------------------------------
' Procedure : guardarNuevo
' DateTime  : 23/06/2008 18:02
' Author    :
' Purpose   :
'---------------------------------------------------------------------------------------
'
Public Function guardarNuevo(bean As bproducto) As Integer
On Error GoTo hnderr
Dim rst As Recordset
Dim sql As String
sql = "select * from proc_producto_inserta(cast('" + bean.sDescripcionCorta + "' as character varying(30)), cast('" + bean.sDescripcionLarga + "' as character varying(200)),"
sql = sql + Format(bean.nPrecio, "#####.00") + "," + CStr(bean.bestado.nCodigo) + "," + CStr(bean.bCategoria.nCodigo) + ",'" + Trim(bean.sCodBarra) + "'," + CStr(bean.bcodigodestino.ncodigodestino) + ",'" + Trim(bean.imagen) + "'," + CStr(bean.btipo.nCodigo) & "," + CStr(bean.balmacen.nCodigo) + ") "
Set rst = mvarConnection.Connection.Execute(sql)
guardarNuevo = UtilConstantes.OPT_DATOS_GUARDADOS
hnderr:
If Err.Number = 0 Then Exit Function
guardarNuevo = UtilConstantes.OPT_ERROR_ENCONTRADO
cloneError Err
Err.Clear
End Function
'---------------------------------------------------------------------------------------
' Procedure : actualizar
' DateTime  : 23/06/2008 18:02
' Author    :
' Purpose   :
'---------------------------------------------------------------------------------------
'
Public Function actualizar(bean As bproducto) As Integer
On Error GoTo hnderr
Dim sql As String
sql = "SELECT * FROM proc_producto_actualiza('" + bean.sDescripcionCorta + "','" + bean.sDescripcionLarga + "'," + CStr(bean.nPrecio) + "," + CStr(bean.bestado.nCodigo) + "," + CStr(bean.bCategoria.nCodigo) + ",'" + bean.sCodBarra + "','" + Trim(bean.imagen) + "'," + CStr(bean.bcodigodestino.ncodigodestino) + "," + CStr(bean.btipo.nCodigo) + "," + CStr(bean.balmacen.nCodigo) + "," + CStr(bean.nCodigo) + ") "
mvarConnection.Connection.Execute sql
actualizar = UtilConstantes.OPT_DATOS_GUARDADOS
hnderr:
If Err.Number = 0 Then Exit Function
actualizar = UtilConstantes.OPT_ERROR_ENCONTRADO
cloneError Err
Err.Clear
End Function
'---------------------------------------------------------------------------------------
' Procedure : getLista
' DateTime  : 16/04/2008 23:54
' Author    :
' Purpose   : Obtiene la lista de productos que coincidan con el parametro
'---------------------------------------------------------------------------------------

Public Function getListaPorCodigo(bean As bproducto) As Collection
On Error GoTo hnderr
Dim sql As String
Dim rst As New Recordset
Dim list As New Collection
Dim record As New bproducto
sql = "SELECT ncodigo , sdescorta , sdeslarga , ncategoria , scategoria,  nestado , sestado , nprecio ,scodbarra,  ntotalregistros , simagen , ndestino, sdestino , ntipo , sdescripcion , nalmdescarga , sdesalmacen from "
sql = sql + " proc_producto_lista_estado ( " + CStr(bean.bestado.nCodigo) + ")"
rst.Open sql, mvarConnection.Connection, adOpenForwardOnly
While Not rst.EOF
    If Not IsNull(rst.Fields("sdescorta")) Then record.sDescripcionCorta = rst.Fields("sdescorta").value
    If Not IsNull(rst.Fields("sdeslarga")) Then record.sDescripcionLarga = rst.Fields("sdeslarga").value
    If Not IsNull(rst.Fields("ncategoria")) Then record.bCategoria.nCodigo = rst.Fields("ncategoria").value
    If Not IsNull(rst.Fields("scategoria")) Then record.bCategoria.sDescripcionCorta = rst.Fields("scategoria").value
    If Not IsNull(rst.Fields("nprecio")) Then record.nPrecio = rst.Fields("nprecio").value
    If Not IsNull(rst.Fields("scodbarra")) Then record.sCodBarra = rst.Fields("scodbarra").value
    If Not IsNull(rst.Fields("simagen")) Then record.imagen = rst.Fields("simagen").value
    If Not IsNull(rst.Fields("ndestino")) Then record.bcodigodestino.ncodigodestino = rst.Fields("ndestino").value
    If Not IsNull(rst.Fields("sdestino")) Then record.bcodigodestino.sdescripcion = rst.Fields("sdestino").value
    If Not IsNull(rst.Fields("ntipo")) Then record.btipo.nCodigo = rst.Fields("ntipo").value
    If Not IsNull(rst.Fields("sdescripcion")) Then record.btipo.sdescripcion = rst.Fields("sdescripcion").value
    If Not IsNull(rst.Fields("nalmdescarga")) Then record.balmacen.nCodigo = rst.Fields("nalmdescarga").value
    If Not IsNull(rst.Fields("sdesalmacen")) Then record.balmacen.sDescripcionLarga = rst.Fields("sdesalmacen").value
    rst.MoveNext
    list.Add record
Wend
Set rst = Nothing
Set getListaPorCodigo = list
hnderr:
If Err.Number = 0 Then Exit Function
Err.Clear
End Function
'---------------------------------------------------------------------------------------
' Procedure : listar
' DateTime  : 16/04/2008 23:54
' Author    :
' Purpose   : Obtiene la lista de productos que coincidan con el parametro
'---------------------------------------------------------------------------------------
'
Public Function getListaPorParametros(bean As bproducto) As Collection
On Error GoTo hnderr
Dim sql As String
Dim rst As New Recordset
Dim list As New Collection
Dim record As New bproducto
sql = "SELECT ncodigo , sdescorta , sdeslarga , ncategoria , scategoria ,"
sql = sql + " nestado , sestado , nprecio ,scodbarra,  ntotalregistros , simagen , ndestino , sdestino , ntipo , sdescripcion , nalmdescarga , sdesalmacen from "
sql = sql + " proc_producto_lista_mantenimiento ( " + CStr(bean.nCodigo) + ",'" + CStr(Trim(bean.sDescripcionCorta)) + "',"
If Not bean.bCategoria Is Nothing Then sql = sql + CStr(bean.bCategoria.nCodigo) Else sql = sql + "0"
sql = sql + ") order by 9 LIMIT 250;"
rst.Open sql, mvarConnection.Connection, adOpenForwardOnly
While Not rst.EOF
    Set record = New bproducto
    If Not IsNull(rst.Fields("nCodigo")) Then record.nCodigo = rst.Fields("nCodigo").value
    If Not IsNull(rst.Fields("sdescorta")) Then record.sDescripcionCorta = rst.Fields("sdescorta").value
    If Not IsNull(rst.Fields("sdeslarga")) Then record.sDescripcionLarga = rst.Fields("sdeslarga").value
    If Not IsNull(rst.Fields("ncategoria")) Then record.bCategoria.nCodigo = rst.Fields("ncategoria").value
    If Not IsNull(rst.Fields("scategoria")) Then record.bCategoria.sDescripcionCorta = rst.Fields("scategoria").value
    If Not IsNull(rst.Fields("nestado")) Then record.bestado.nCodigo = rst.Fields("nestado").value
    If Not IsNull(rst.Fields("sestado")) Then record.bestado.sdescripcion = rst.Fields("sestado").value
    If Not IsNull(rst.Fields("nprecio")) Then record.nPrecio = rst.Fields("nprecio").value
    If Not IsNull(rst.Fields("scodbarra")) Then record.sCodBarra = rst.Fields("scodbarra").value
    If Not IsNull(rst.Fields("simagen")) Then record.imagen = rst.Fields("simagen").value
    If Not IsNull(rst.Fields("ndestino")) Then record.bcodigodestino.ncodigodestino = rst.Fields("ndestino").value
    If Not IsNull(rst.Fields("sdestino")) Then record.bcodigodestino.sdescripcion = rst.Fields("sdestino").value
    If Not IsNull(rst.Fields("ntipo")) Then record.btipo.nCodigo = rst.Fields("ntipo").value
    If Not IsNull(rst.Fields("sdescripcion")) Then record.btipo.sdescripcion = rst.Fields("sdescripcion").value
    If Not IsNull(rst.Fields("nalmdescarga")) Then record.balmacen.nCodigo = rst.Fields("nalmdescarga").value
    If Not IsNull(rst.Fields("sdesalmacen")) Then record.balmacen.sDescripcionLarga = rst.Fields("sdesalmacen").value
    rst.MoveNext
    list.Add record
Wend
Set getListaPorParametros = list
hnderr:
If Err.Number = 0 Then Exit Function
Err.Clear
End Function
Public Function getListaPorDescripcion(bean As bproducto) As Collection
On Error GoTo hnderr
Dim sql As String
Dim rst As New Recordset
Dim list As New Collection
Dim record As New bproducto
sql = "SELECT ncodigo , sdescorta , sdeslarga , ncategoria , scategoria ,"
sql = sql + " nestado , sestado , nprecio ,scodbarra,  ntotalregistros , simagen , ndestino, sdestino from "
sql = sql + " proc_producto_lista_descripcion ('" + CStr(bean.sDescripcionCorta) + "','" + CStr(Trim(bean.sDescripcionLarga)) + "')"
rst.Open sql, mvarConnection.Connection, adOpenForwardOnly
While Not rst.EOF
    Set record = New bproducto
    If Not IsNull(rst.Fields("ncodigo")) Then record.nCodigo = rst.Fields("nCodigo").value
    If Not IsNull(rst.Fields("sdescorta")) Then record.sDescripcionCorta = rst.Fields("sdescorta").value
    If Not IsNull(rst.Fields("sdeslarga")) Then record.sDescripcionLarga = rst.Fields("sdeslarga").value
    If Not IsNull(rst.Fields("ncategoria")) Then record.bCategoria.nCodigo = rst.Fields("ncategoria").value
    If Not IsNull(rst.Fields("scategoria")) Then record.bCategoria.sDescripcionCorta = rst.Fields("scategoria").value
    If Not IsNull(rst.Fields("nestado")) Then record.bestado.nCodigo = rst.Fields("nestado").value
    If Not IsNull(rst.Fields("sestado")) Then record.bestado.sdescripcion = rst.Fields("sestado").value
    If Not IsNull(rst.Fields("nprecio")) Then record.nPrecio = rst.Fields("nprecio").value
    If Not IsNull(rst.Fields("scodbarra")) Then record.sCodBarra = rst.Fields("scodbarra").value
    If Not IsNull(rst.Fields("simagen")) Then record.imagen = rst.Fields("simagen").value
    If Not IsNull(rst.Fields("ndestino")) Then record.bcodigodestino.ncodigodestino = rst.Fields("ndestino").value
    If Not IsNull(rst.Fields("sdestino")) Then record.bcodigodestino.sdescripcion = rst.Fields("sdestino").value
    rst.MoveNext
    list.Add record
Wend
Set getListaPorDescripcion = list
hnderr:
If Err.Number = 0 Then Exit Function
Err.Clear
End Function
